<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateProjectNodeReportTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        $table = $this->table('project_node_report', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '日报上报表（备注功能）']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('project_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '项目id'])
            ->addColumn('report_date', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '上报日期（eg:20231211）'])
            ->addColumn('step_category_id', 'string', ['default' => '', 'limit' => 100, 'comment' => '环节ID'])
            ->addColumn('json', 'json', ['null' => true, 'comment' => '备注信息'])
            ->addColumn('created', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '创建时间'])
            ->addColumn('created_by', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '创建者'])
            ->addIndex(['project_id', 'report_date'], ['type' => 'normal', 'name' => 'project_report']);
        // 创建表
        $table->create();
    }

    public function down()
    {
        $this->table('project_node_report')->drop()->save();
    }

}
